<template>
    <div>

    </div>
</template>

<script>
export default {
    async created() {
        let res = await this.Api({url:"https://xweik.com/ggao/web_findGgaoInfoGridHomeByNameFnId.action"})
        console.log(res,"res");
    },
    methods: {
        Api ({ url, method = 'GET' }) {
            return new Promise((resolve, reject) => {
                const xhr = new XMLHttpRequest();
                xhr.open(method, url);
                xhr.responseType = 'json';

                // for (let x in header) {
                // xhr.setRequestHeader(x, header[x]);
                // }
                xhr.setRequestHeader("Access-Control-Allow-Origin", "http://www.domain1.com");
                xhr.send();

                xhr.onreadystatechange = function () {
                    console.log(xhr);
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        resolve(xhr.response);
                        // resolve才有api({}).then()方法
                    }
                }
            })
        }
    }
}
</script>

<style>

</style>